package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.logic.bussiness.player.UserHistoryAttributeBussiness;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.date.DateHelper;
import io.netty.channel.ChannelHandlerContext;

/**
 * @Author wpj
 * @Date 2020/10/17
 */
@Cmd(code = GameProtocol.S_HUA_SHI_GANG_GET_ABILITY_FROM_CROSS, desc = "花石纲系统通知")
public class HuaShiGangGetAbilityFromCrossCmd implements Command {

    int activityId;

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        HuaShiGangProto.HuaShiGangGetAbilityReqMsg msg = HuaShiGangProto.HuaShiGangGetAbilityReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        long lastDayZeroTime = (DateHelper.getTodayZeroTimeStamp() - 24 * 3600 * 1000) / 1000;
        long allAbility = UserHistoryAttributeBussiness.getAllHistoryByLoginUser(lastDayZeroTime);
        HuaShiGangProto.HuaShiGangGetAbilityRespMsg.Builder builder = HuaShiGangProto.HuaShiGangGetAbilityRespMsg.newBuilder();
        builder.setAbility(allAbility);
        builder.setActivityId(activityId);
        GamePlayerMgr.sendPacket(0, YanQuMessageUtils.buildMessage(CrossProtocol.C2_HUA_SHI_GANG_USER_NOTIFY_ABILITY, builder));
    }
}
